package com.example.a_java.mapper;

import com.example.a_java.entity.ProductFeature;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 产品审核特性Mapper接口
 */
@Mapper
public interface ProductApprovalFeatureMapper {
    /**
     * 根据审核ID查询特性列�?
     *
     * @param approvalId 审核ID
     * @return 特性列�?
     */
    @Select("SELECT approval_id, `key`, name, value FROM t_product_approval_feature WHERE approval_id = #{approvalId}")
    @Results(id = "approvalFeatureResultMap", value = {
        @Result(property = "productId", column = "approval_id"),
        @Result(property = "key", column = "key"),
        @Result(property = "name", column = "name"),
        @Result(property = "value", column = "value")
    })
    List<ProductFeature> selectFeaturesByApprovalId(@Param("approvalId") Long approvalId);

    /**
     * 批量插入产品审核特�?
     *
     * @param approvalId 审核ID
     * @param features   特性列�?
     * @return 影响行数
     */
    @Insert({
        "<script>",
        "INSERT INTO t_product_approval_feature (approval_id, `key`, name, value)",
        "VALUES",
        "<foreach collection='features' item='feature' separator=','>",
        "  (#{approvalId}, #{feature.key}, #{feature.name}, #{feature.value})",
        "</foreach>",
        "</script>"
    })
    int batchInsertFeatures(@Param("approvalId") Long approvalId, @Param("features") List<ProductFeature> features);

    /**
     * 删除产品审核特�?
     *
     * @param approvalId 审核ID
     * @return 影响行数
     */
    @Delete("DELETE FROM t_product_approval_feature WHERE approval_id = #{approvalId}")
    int deleteFeaturesByApprovalId(@Param("approvalId") Long approvalId);
} 
